package apiwork.lcbmi.fillers;

import com.opensymphony.xwork2.util.ValueStack;

public class OgnlExpressionFiller implements Filler {
	private ValueStack stack;
	private String condition;
	private String expression;
	private Object value;
	
	public OgnlExpressionFiller(){};
    
	public void fillin(Object action) {
		Boolean answer = false;
        try {
        	if (null != condition && !("".equals(condition.trim()))) {
	            boolean pop = false;
	            if (!stack.getRoot().contains(action)) {
	                stack.push(action);
	                pop = true;
	            }
	            Object obj = stack.findValue(condition);
	            if (pop) {
	                stack.pop();
	            }
	            if ((obj != null) && (obj instanceof Boolean)) {
	                answer = (Boolean) obj;
	            }
            }else{
            	answer = true;
            }
//        	System.out.println("findvalue("+expression+")"+stack.findValue(expression));
        	if (answer) {
            	stack.setValue(expression, value);
//            	stack.setValue("fillField", expression);
            }
        } catch (Exception e) {
//        	e.printStackTrace();
        }
	}

	public void setExpression(String expression) {
        this.expression = expression;
    }

    public String getExpression() {
        return expression;
    }

	public void setValueStack(ValueStack stack) {
		this.stack = stack;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}
    
}
